package com.springboot.demo.seria_deseria.controller;

import com.sanbi.common.vo.ResponseVo;
import com.springboot.demo.seria_deseria.bean.AuthLoginReqVo;
import com.springboot.demo.seria_deseria.bean.GoodsOnSaleParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.springboot.demo.seria_deseria.bean.User;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author 江南一点雨
 * @Site www.javaboy.org 2019-06-05 9:38
 */
@RestController
@Api(tags = "用户管理接口")
@RequestMapping("user")
public class UserController {

    @ApiOperation("根据id查询用户")
    @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "99")
    @GetMapping("getUserById")
    public User getUserById(Integer id) {
        User user = new User();
        user.setId(id);
        return user;
    }

    @ApiOperation("根据id更新用户名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "99"),
            @ApiImplicitParam(name = "username", value = "用户名", defaultValue = "javaboy")
    })
    @PutMapping("updateUsernameById")
    public User updateUsernameById(String username, Integer id) {
        User user = new User();
        user.setId(id);
        user.setUsername(username);
        return user;
    }

    @PostMapping("addUser")
    @ApiOperation("添加用户")
    public User addUser(@RequestBody User user) {
        return user;
    }

    @DeleteMapping("deleteUserById/{id}")
    @ApiOperation("根据id 删除用户")
    public void deleteUserById(@PathVariable Long id) {

    }

    @GetMapping("hello")
    public String hello(String name) {
        return "hello " + name + " !";
    }

//    @PostMapping("/userRegistration")
//    public ResponseVo userRegistration(@RequestBody @Valid UserVo userVo) {
//        userService.registerUser(userVo.getUsername());
//        return CommonResult.ok();
//    }

    @PostMapping("login")
    @ApiOperation("使用账号密码登录")
    public ResponseVo login(@Valid @RequestBody AuthLoginReqVo reqVo) {
        return ResponseVo.ok();
    }

    @ApiOperation("商品上架")
    @PostMapping("/onSale")
    public ResponseVo onSale(@RequestBody @Valid GoodsOnSaleParam param) {
        return ResponseVo.ok();
    }
}
